﻿using System.Threading;
using System;
using System.IO;

using log4net;

using Pink.Scheduler.Shared;

namespace TestTasks
{
	/// <summary>
	/// Простая задача, умеющая только ждать.
	/// </summary>
	public class SimpleTaskImplementation : ITask, IDomainInitializer
	{
		#region ITask Members
		public void Execute(string key, string config, int executionID)
		{
			ILog logger = LogManager.GetLogger(GetType());
			logger.Info("Запуск!");
			Random r = new Random();
			for (int i = 0; i < 20; i++)
			{
				int result = r.Next(10);
				logger.Debug(result);
				if (result == 0)
					throw new Exception();
				if (result == 1)
					Thread.Sleep(1000);
			}
		}

		#endregion

		#region IDomainInitializer Members

		public void InitializeDomain()
		{
			log4net.Config.XmlConfigurator.Configure(new FileInfo("./log4net.config"));
		}

		#endregion
	}
}